package com.ygp.asyn.enums;


import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

@Getter
public enum FileTypeEnum {

    /**
     * zip文件
     */
    ZIP(1, ".zip"),
    /**
     * xlsx 文件
     */
    XLSX(2, ".xlsx"),
    PNG(3, ".png"),
    DEFAULT(-1, ""),
    ;
    @Getter
    private Integer code;
    @Getter
    private String extension;

    private static final Map<String, FileTypeEnum> codeMap = new HashMap<>();

    static {
        FileTypeEnum[] values = FileTypeEnum.values();
        for (FileTypeEnum value : values) {
            codeMap.put(value.getCode().toString(), value);
        }
    }

    FileTypeEnum(Integer code, String extension) {
        this.code = code;
        this.extension = extension;
    }

    public static String getExtensionByCode(Object code) {
        return codeMap.getOrDefault(String.valueOf(code), DEFAULT).getExtension();
    }

    public static FileTypeEnum getFileTypeEnum(Object code) {
        return codeMap.getOrDefault(String.valueOf(code), DEFAULT);
    }

}
